import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { EliteTowerFloorButton } from "./EliteTowerFloorButton";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { ItemsBox } from "../../common/item/ItemsBox";
import { Cache } from "../../../cache/Cache";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { EliteTowerFloorData } from "./EliteTowerFloorData";
import { DataEvent } from "../../../events/DataEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class EliteTowerPanel
    
    export  class EliteTowerPanel extends GSprite
    {
        constructor()
        {
            super();
            this._floorVec = new Vector.<EliteTowerFloorButton>();
            ObjCreate.createBg(0, 0, 373, 451, this);
            this.addChild(new GImageBitmap(ImagesConst.GuildEliteTowerBg, 1, 1));
            this._towerSp = new GSprite();
            this.addChild(this._towerSp);
            this.addFloor(1, 106, 255);
            this.addFloor(2, 114, 206);
            this.addFloor(3, 121, 168);
            this.addFloor(4, 122, 121);
            this.addFloor(5, 133, 87);
            this.addFloor(6, 134, 51);
            this.addFloor(7, 144, 4);
            this._bottomBg = new GBitmap();
            this._bottomBg.x = 1;
            this._bottomBg.y = 370;
            this.addChild(this._bottomBg);
            this._itemsBox = new ItemsBox();
            this._itemsBox.x = this._bottomBg.x + 26;
            this._itemsBox.y = this._bottomBg.y + 38;
            this._itemsBox.setItems([13014000, 13024000, 13034000, 13044000, 13054000, 13064000, 13074000, 13004000]);
            this.addChild(this._itemsBox);
            this._dataProvider = Cache.instance.guildElite.eliteTowerDataProvider;
            this.selectedFloor = 0;
            return;
        }

        /* internal  */addFloor(arg1: int, arg2: int, arg3: int): void
        {
            var loc1;
            (loc1 = new EliteTowerFloorButton(arg1)).x = arg2;
            loc1.y = arg3;
            loc1.addEventListener(GModuleEvent.GuildElite_FloorSelectedChange, this.onFloorSelectedChangeHandler);
            this._towerSp.addChild(loc1);
            this._floorVec.push(loc1);
            return;
        }

        public onResLoaded(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._floorVec;
            for(loc1 of loc3) 
            {
                loc1.updateUrl();
            }
            this._bottomBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildEliteBottomBg);
            return;
        }

        public set selectedFloor(arg1: int)
        {
            this._selectedFloor = arg1;
            this.updateDataProvider();
            return;
        }

        public get selectedFloor(): int
        {
            return this._selectedFloor;
        }

        public glowEffect(): void
        {
            EffectManager.glowFilterReg(this._towerSp, [FilterConst.uiBtnFilter], 1, 13, 0, 3);
            return;
        }

        public get selectedFloorData(): EliteTowerFloorData
        {
            if (this._dataProvider == null) 
            {
                return null;
            }
            if (this.selectedFloor == 0) 
            {
                return null;
            }
            return this._dataProvider.getItemAt((this.selectedFloor - 1)) as EliteTowerFloorData;
        }

        /* internal  */onFloorSelectedChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as EliteTowerFloorData;
            this.selectedFloor = loc1.floor;
            return;
        }

        /* internal  */updateDataProvider(): void
        {
            var loc1=null;
            if (this._dataProvider == null) 
            {
                return;
            }
            var loc2=0;
            while (loc2 < this._dataProvider.length) 
            {
                loc1 = this._dataProvider.getItemAt(loc2) as EliteTowerFloorData;
                if (loc1.floor != this.selectedFloor) 
                {
                    loc1.selected = false;
                }
                else 
                {
                    loc1.selected = true;
                }
                this._floorVec[loc2].updateData(loc1);
                ++loc2;
            }
            return;
        }

        /* internal */ /* var */_bottomBg: GBitmap;

        /* internal */ /* var */_itemsBox: ItemsBox;

        /* internal */ /* var */_towerSp: GSprite;

        /* internal */ /* var */_dataProvider: DataProvider;

        /* internal */ /* var */_selectedFloor: int;

        /* internal */ /* var */_floorVec: Vector.<EliteTowerFloorButton>;
    }
